<#if classPath??>
package ${classPath};
</#if>
import org.springframework.beans.factory.annotation.Autowired;
import ${classPathShort}.service.${Service};
import ${classPathShort}.model.${Entity};
import ${classPathShort}.model.dto.${DTO};
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import com.cloume.commons.rest.response.RestResponse;
import com.cloume.commons.rest.response.PagingRestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@Log4j2
@Api(tags = {"<#if tableDesc ? has_content>${tableDesc?trim?replace('\n', '')}管理  <#else> 前端控制器</#if>"})
@RestController
@RequestMapping("/")
public class ${Controller} {

    @Resource
    private  ${Service} ${Service ? uncap_first};


        @ApiOperation(value = "<#if tableDesc?has_content>查询所有${tableDesc?trim?replace('\n', '')}<#else>查询所有  </#if>")
        @GetMapping("/findAll${Entity}")
        public RestResponse findAll${Entity}() {
                List<${Entity}> allList = ${Service ? uncap_first}.findAll${Entity}();
                return RestResponse.good(allList);
        }
        @ApiOperation(value = "<#if tableDesc?has_content>根据Id查询${tableDesc?trim?replace('\n', '')}详情<#else>根据Id查询  </#if>")
        @GetMapping("/${Entity? uncap_first}/{id}")
        public RestResponse find${Entity}ById(@PathVariable("id") ${idType} id) {
                ${Entity} ${Entity? uncap_first} = ${Service ? uncap_first}.find${Entity}ById(id);
                return RestResponse.good(${Entity? uncap_first});
        }

        @ApiOperation(value = "<#if tableDesc?has_content>分页查询${tableDesc?trim?replace('\n', '')}列表<#else>分页查询 </#if>")
        @PostMapping("/page/${Entity? uncap_first}")
        public PagingRestResponse  find${Entity}ByPage(@RequestBody ${DTO}  ${DTO ? uncap_first}) {
                Page<${Entity}> pageVo = ${Service ? uncap_first}.find${Entity}ByPage(${DTO ? uncap_first});
                return PagingRestResponse.good(pageVo.getContent(),pageVo.getTotalElements());
        }

        @ApiOperation(value = "<#if tableDesc?has_content>新增${tableDesc?trim?replace('\n', '')}<#else>新增  </#if>")
        @PostMapping("")
        public RestResponse add${Entity}(@RequestBody ${DTO} ${DTO ? uncap_first}) {
                ${Entity} ${Entity ? uncap_first}=${Service ? uncap_first}.add${Entity}(${DTO? uncap_first});
                return RestResponse.good(${Entity ? uncap_first});
        }

        @ApiOperation(value = "<#if tableDesc?has_content>更新${tableDesc?trim?replace('\n', '')}<#else>更新  </#if>")
        @PutMapping("")
        public RestResponse update${Entity}(@RequestBody ${DTO} ${DTO ? uncap_first}) {
                ${Entity} ${Entity ? uncap_first}=${Service ? uncap_first}.update${Entity}(${DTO? uncap_first});
                return RestResponse.good(${Entity ? uncap_first});
            }

        @ApiOperation(value = "<#if tableDesc?has_content>删除${tableDesc?trim?replace('\n', '')}<#else>删除  </#if>")
        @DeleteMapping("")
        public RestResponse delete${Entity}(@RequestParam(value = "ids") ${List}<${idType}> ids){
            ${Service ? uncap_first}.delete${Entity}(ids);
            return RestResponse.good("ok");
            }
}